﻿Public Class CheckInPage
    Public adults As Label
    Public children As Label
    Public adultsList As ComboBox
    Public childrenlist As ComboBox
    Public duration As Label
    Public startDate As Label
    Public endDate As Label
    Public durationTextBox As TextBox
    Public panel As Panel
    Public nextButton As Button
    Public backButton As Button
    Public startDatePicker As DateTimePicker
    Public endDatePicker As DateTimePicker

    Public Sub CheckInClicked()

        panel = New Windows.Forms.Panel
        panel.Name = "cIPanel"
        panel.Size = New System.Drawing.Size(800, 500)
        panel.Location = New System.Drawing.Point(0, 0)
        panel.BackgroundImage = Image.FromFile _
            (System.Environment.GetFolderPath _
            (System.Environment.SpecialFolder.Personal) _
            & "\bckgrnd.png")

        Adults = New Windows.Forms.Label
        Adults.Name = "adults"
        Adults.Location = New System.Drawing.Point(10, 13)
        Adults.Size = New System.Drawing.Size(42, 20)
        Adults.Text = "Adults: "
        adults.BackColor = Color.Transparent

        Children = New Windows.Forms.Label
        Children.Name = "children"
        children.Location = New System.Drawing.Point(112, 13)
        children.Size = New System.Drawing.Size(49, 20)
        children.Text = "Children:"
        children.BackColor = Color.Transparent

        adultsList = New Windows.Forms.ComboBox
        adultsList.Name = "adultsList"
        adultsList.Location = New System.Drawing.Point(52, 10)
        adultsList.Size = New System.Drawing.Point(50, 20)
        adultsList.Items.Add(1)
        adultsList.Items.Add(2)
        adultsList.Items.Add(3)
        adultsList.Items.Add(4)
        adultsList.Items.Add(5)
        adultsList.Items.Add(6)
        adultsList.Items.Add(7)
        adultsList.Items.Add(8)
        adultsList.Items.Add(9)
        adultsList.Items.Add(10)
        adultsList.SelectedIndex = 0

        childrenlist = New Windows.Forms.ComboBox
        childrenlist.Name = "childrenList"
        childrenlist.Location = New System.Drawing.Point(162, 10)
        childrenlist.Size = New System.Drawing.Point(50, 20)
        childrenlist.Items.Add(0)
        childrenlist.Items.Add(1)
        childrenlist.Items.Add(2)
        childrenlist.Items.Add(3)
        childrenlist.Items.Add(4)
        childrenlist.Items.Add(5)
        childrenlist.Items.Add(6)
        childrenlist.Items.Add(7)
        childrenlist.Items.Add(8)
        childrenlist.Items.Add(9)
        childrenlist.Items.Add(10)
        childrenlist.SelectedIndex = 0

        duration = New Windows.Forms.Label
        duration.Name = "duration"
        duration.Location = New System.Drawing.Point(10, 73)
        duration.Size = New System.Drawing.Size(150, 20)
        duration.Text = "Duration of Stay (in days):"
        duration.BackColor = Color.Transparent

        durationTextBox = New Windows.Forms.TextBox
        durationTextBox.Name = "durationTextBox"
        durationTextBox.Location = New System.Drawing.Point(160, 70)
        durationTextBox.TabIndex = 0
        durationTextBox.Enabled = False

        startDate = New Windows.Forms.Label
        startDate.Name = "startDate"
        startDate.Location = New System.Drawing.Point(10, 43)
        startDate.Text = "Start Date: "
        startDate.BackColor = Color.Transparent

        endDate = New Windows.Forms.Label
        endDate.Name = "endDate"
        endDate.Location = New System.Drawing.Point(10, 103)
        endDate.Text = "End Date: "
        endDate.BackColor = Color.Transparent

        startDatePicker = New Windows.Forms.DateTimePicker
        startDatePicker.Name = "startDatePicker"
        startDatePicker.Location = New System.Drawing.Point(160, 40)
        startDatePicker.Value = Today

        endDatePicker = New Windows.Forms.DateTimePicker
        endDatePicker.Name = "endDatePicker"
        endDatePicker.Location = New System.Drawing.Point(160, 100)
        endDatePicker.Value = Today

        nextButton = New Windows.Forms.Button
        nextButton.Name = "nextButton"
        nextButton.Location = New System.Drawing.Point(500, 325)
        nextButton.Size = New System.Drawing.Size(125, 125)
        nextButton.Text = "Next"
        nextButton.BackColor = Color.White

        backButton = New Windows.Forms.Button
        backButton.Name = "backButton"
        backButton.Location = New System.Drawing.Point(645, 325)
        backButton.Size = New System.Drawing.Size(125, 125)
        backButton.Text = "Back to Main Menu"
        backButton.BackColor = Color.White

        AddHandler nextButton.Click, AddressOf nextButton_Click
        AddHandler backButton.Click, AddressOf backButton_Click

        AddHandler startDatePicker.ValueChanged, AddressOf startDate_valueChanged
        AddHandler endDatePicker.ValueChanged, AddressOf endDate_valueChanged

        panel.Controls.Add(adults)
        panel.Controls.Add(adultsList)
        panel.Controls.Add(Children)
        panel.Controls.Add(childrenlist)
        panel.Controls.Add(startDate)
        panel.Controls.Add(endDate)
        panel.Controls.Add(startDatePicker)
        panel.Controls.Add(endDatePicker)
        panel.Controls.Add(duration)
        panel.Controls.Add(durationTextBox)
        panel.Controls.Add(backButton)
        panel.Controls.Add(nextButton)
        Form1.Controls.Add(panel)
    End Sub

    Private Sub nextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim mp As New MapPage()
        mp.ShowMap()
        mp.panel.BringToFront()

    End Sub
    Private Sub backButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        panel.SendToBack()

    End Sub

    Private Sub startDate_valueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If (endDatePicker.Value >= startDatePicker.Value And startDatePicker.Value >= Today) Then
            durationTextBox.Text = DateDiff("d", startDatePicker.Value, endDatePicker.Value) + 1
        ElseIf (startDatePicker.Value < Today) Then
            MsgBox("Start date cannot occurs before today", vbInformation)
            startDatePicker.Value = Today
        Else
            MsgBox("Start date cannot occurs after end date. Please re-choose end date", vbInformation)
            startDatePicker.Value = endDatePicker.Value
        End If
    End Sub

    Private Sub endDate_valueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If (endDatePicker.Value >= startDatePicker.Value) Then
            durationTextBox.Text = DateDiff("d", startDatePicker.Value, endDatePicker.Value) + 1

        Else
            MsgBox("End date cannot occurs before start date. Please re-choose end date", vbInformation)
            endDatePicker.Value = startDatePicker.Value
        End If
    End Sub
End Class
